//
//  MoneyInfoTableViewCell.m
//  work
//
//  Created by 徐宏飞 on 16/6/3.
//  Copyright © 2016年 方伟. All rights reserved.
//

#import "MoneyInfoTableViewCell.h"
#import "WorkerInfoModel.h"


@interface MoneyInfoTableViewCell ()
@property (nonatomic, strong) UILabel *lblTotalnum;             //总和

@property (nonatomic, strong) UILabel *lblIncomeTitle;          //收益
@property (nonatomic, strong) UILabel *lblIncomeContent;

@property (nonatomic, strong) UILabel *lblRewardTitle;          //平台奖励
@property (nonatomic, strong) UILabel *lblRewardContent;

@property (nonatomic, strong) UILabel *lblRedEnvelopeTitle;     //红包
@property (nonatomic, strong) UILabel *lblRedEnvelopeContent;

@property (nonatomic, strong) UIButton *btnWithdraw;            //提现
@property (nonatomic, strong) UIButton *btnBill;                //账单
@end

@implementation MoneyInfoTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}



- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.backgroundColor = WHITE;
        
        [self addSubview:self.lblTotalnum];
        
        [self addSubview:self.lblIncomeTitle];
        [self addSubview:self.lblIncomeContent];
        
        [self addSubview:self.lblRewardTitle];
        [self addSubview:self.lblRewardContent];
        
        [self addSubview:self.lblRedEnvelopeTitle];
        [self addSubview:self.lblRedEnvelopeContent];
        
        
        [self addSubview:self.btnWithdraw];
        [self addSubview:self.btnBill];
        
    }
    return self;
}




#pragma mark - event response
//提现
- (void)btnWithdrawAction{
    NSLog(@"提现");
    [self.delegate moneyCellPushToNextPageWithtype:0];
}

- (void)btnBillAction{
    NSLog(@"账单");
    [self.delegate moneyCellPushToNextPageWithtype:1];
}



#pragma mark - private methods
- (UILabel *)createLableFrame:(CGRect)frame center:(CGPoint)point textColor:(UIColor *)color font:(UIFont *)font text:(NSString *)text{
    UILabel *label = [[UILabel alloc] initWithFrame:frame];
    label.textColor = color;
    label.center = point;
    label.textAlignment = NSTextAlignmentCenter;
    label.font = font;
    label.text = text;
    label.numberOfLines = 0;
    //    label.lineBreakMode =
    return label;
}




#pragma mark - gettsers and setters

- (UILabel *)lblTotalnum{
    if (!_lblTotalnum) {
        _lblTotalnum = [self createLableFrame:CGRectMake(0, 0, 250*WID, 35*WID)
                                       center:CGPointMake(140*WID, 15*WID)
                                    textColor:UIColorFromRGB(0x525252)
                                         font:FW_XWID_FONT(15)
                                         text:@"总金额:"];
        _lblTotalnum.textAlignment = NSTextAlignmentLeft;
    }
    return _lblTotalnum;
}



- (UILabel *)lblIncomeTitle{
    if (!_lblIncomeTitle) {
        _lblIncomeTitle = [self createLableFrame:CGRectMake(0, 0, 100*WID, 20*WID)
                                          center:CGPointMake(50*WID, 70*WID)
                                       textColor:UIColorFromRGB(0xA4AAB3)
                                            font:FW_XWID_FONT(14)
                                            text:@"收益"];
        
    }
    return _lblIncomeTitle;
}


- (UILabel *)lblIncomeContent{
    if (!_lblIncomeContent) {
        _lblIncomeContent = [self createLableFrame:CGRectMake(0, 0, 100*WID, 20*WID)
                                            center:CGPointMake(50*WID, 45*WID)
                                         textColor:UIColorFromRGB(0x525252)
                                              font:FW_XWID_FONT(24)
                                              text:@"5000"];
        
    }
    return _lblIncomeContent;
}






- (UILabel *)lblRewardTitle{
    if (!_lblRewardTitle) {
        _lblRewardTitle = [self createLableFrame:CGRectMake(0, 0, 100*WID, 20*WID)
                                          center:CGPointMake(SCREEN_WIDTH *0.5, 70*WID)
                                       textColor:UIColorFromRGB(0xA4AAB3)
                                            font:FW_XWID_FONT(14)
                                            text:@"平台奖励"];
    }
    return _lblRewardTitle;
}


- (UILabel *)lblRewardContent{
    if (!_lblRewardContent) {
        _lblRewardContent = [self createLableFrame:CGRectMake(0, 0, 100*WID, 20*WID)
                                            center:CGPointMake(SCREEN_WIDTH *0.5, 45*WID)
                                         textColor:UIColorFromRGB(0x525252)
                                              font:FW_XWID_FONT(24)
                                              text:@"10000"];
    }
    return _lblRewardContent;
}





- (UILabel *)lblRedEnvelopeTitle{
    if (!_lblRedEnvelopeTitle) {
        _lblRedEnvelopeTitle = [self createLableFrame:CGRectMake(0, 0, 100*WID, 20*WID)
                                               center:CGPointMake(SCREEN_WIDTH - 50*WID, 70*WID)
                                            textColor:UIColorFromRGB(0xA4AAB3)
                                                 font:FW_XWID_FONT(14)
                                                 text:@"红包"];
    }
    return _lblRedEnvelopeTitle;
}


- (UILabel *)lblRedEnvelopeContent{
    if (!_lblRedEnvelopeContent) {
        _lblRedEnvelopeContent = [self createLableFrame:CGRectMake(0, 0, 100*WID, 20*WID)
                                                 center:CGPointMake(SCREEN_WIDTH - 50*WID, 45*WID)
                                              textColor:UIColorFromRGB(0x525252)
                                                   font:FW_XWID_FONT(24)
                                                   text:@"100"];
    }
    return _lblRedEnvelopeContent;
}


- (UIButton *)btnWithdraw{
    if (!_btnWithdraw) {
        _btnWithdraw = [UIButton buttonWithType:UIButtonTypeCustom];
        _btnWithdraw.frame = CGRectMake(0, 0, 150*WID, 30*WID);
        _btnWithdraw.center = CGPointMake(SCREEN_WIDTH*0.5 - 90*WID, 100*WID);
        _btnWithdraw.titleLabel.font = FW_XWID_FONT(14);
        [_btnWithdraw setTitle:@"提现申请" forState:UIControlStateNormal];
        [_btnWithdraw setBackgroundImage:FW_IMAGE(@"橘色按钮") forState:UIControlStateNormal];
        [_btnWithdraw.layer setMasksToBounds:YES];
        [_btnWithdraw.layer setCornerRadius:5.0]; //设置矩形四个圆角半径
        [_btnWithdraw addTarget:self action:@selector(btnWithdrawAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _btnWithdraw;
}

- (UIButton *)btnBill{
    if (!_btnBill) {
        _btnBill = [UIButton buttonWithType:UIButtonTypeCustom];
        _btnBill.frame = CGRectMake(0, 0, 150*WID, 30*WID);
        _btnBill.center = CGPointMake(SCREEN_WIDTH*0.5 + 90*WID, 100*WID);
        _btnBill.titleLabel.font = FW_XWID_FONT(14);
        [_btnBill setTitle:@"账单" forState:UIControlStateNormal];
        [_btnBill setBackgroundImage:FW_IMAGE(@"绿色按钮") forState:UIControlStateNormal];
        [_btnBill.layer setMasksToBounds:YES];
        [_btnBill.layer setCornerRadius:5.0]; //设置矩形四个圆角半径
        [_btnBill addTarget:self action:@selector(btnBillAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _btnBill;
}

-(void)setModel:(WorkerInfoModel *)model{
    _model = model;
    
    self.lblIncomeContent.text = [NSString stringWithFormat:@"%ld", _model.income_order.integerValue];
    self.lblRewardContent.text = [NSString stringWithFormat:@"%ld", _model.income_platform.integerValue];
    self.lblRedEnvelopeContent.text = [NSString stringWithFormat:@"%ld", _model.income_purse.integerValue];
    if (100 <= _model.balance_withdrawing.integerValue && _model.balance_withdrawing.integerValue<=20000 ) {
        self.lblTotalnum.text = [NSString stringWithFormat:@"总金额:%ld元(%ld元提现中)",_model.balance.integerValue, _model.balance_withdrawing.integerValue];
    } else {
        self.lblTotalnum.text = [NSString stringWithFormat:@"总金额:%ld",_model.balance.integerValue];
    }
    
    
    
}










- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
